const Router = require('koa-router')
const {Auth} = require('../../../middlewares/auth')
const {LikeValidator} = require('../../validators/validator')
const {handleResult} = require('../../lib/helper')
const {Favor} = require('../../model/favorModel')
const router = new Router({
    prefix: "/v1/like"
})


router.post('/', new Auth().m, async(ctx, next)=> {
  console.log('进入了v1/like')
  console.log(ctx.request.body)
  const v = await new LikeValidator().validate(ctx, {
    id: 'art_id' // 更名
  })
  console.log(v.get('body.art_id'))
  await Favor.like(
    v.get('body.art_id'),
    v.get('body.type'),
    ctx.auth.uid
  ) 

  handleResult()
})


router.post('/cancel', new Auth().m, async (ctx, next) => {
  const v = await new LikeValidator().validate(ctx, {
      id: 'art_id'
  });

  await Favor.dislike(
      v.get('body.art_id'),
      v.get('body.type'),
      ctx.auth.uid
  )

  handleResult()
})


module.exports = router

